#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import test
import signal
import sys
from time import sleep
from os import popen, system, _exit
import ppp_test
import test

signal_flag = True

def sigint_handler(signum, frame):
    print 'catched interrupt signal!'
    global signal_flag
    if signal_flag:
        connect = popen("./../cfg/ppp/air-ppp-status").read()
        if cmp(connect, "connected\n") == 0:
            system("./../cfg/ppp/air-ppp-off")
        if ppp_test.thread != None and ppp_test.thread.isAlive():
            ppp_test.cancel_event.set()
            ppp_test.thread.join()
        test.test_object.test_exit()
        signal_flag = False
        # sys.exit(5)
        _exit(5)

def sigint():
    signal.signal(signal.SIGINT, sigint_handler)
